< previous page page_432 next page >

Page 432

9f31265bb40b592b1929e18a47ab28e5.gif
   frmNewEmp.EmpID = lstNames.ItemData(lstNames.ListIndex)

   frmNewEmp.Show
End Sub
The New keyword in the line that assigns the form to the object variable, frmNewEmp, is what informs Visual Basic to make a new instance of the form frmEmployee. This form has an EmpID property thats used by the Employee Information form to retrieve the particular employee selected from the list.
All the properties of the frmEmployee form are duplicated, and a new Form object variable is created. You may only use the New keyword with specific form variables, not generic form variables, generic controls, or specific control variables.
One important point to note is that the frmEmployee form is never loaded, its only used to make a copy of itself for these new variables. You must use the variable frmNewEmp in this procedure to reference that form. If you attempt to reference frmEmployee, youll load the original form, which is different than the frmNewEmp form.
Summary
Object variables are used to write generic, general-purpose code that can be used by multiple applications. This is a very powerful capability, enabling programmers to reuse forms, controls, and code. The Set statement is always used to assign object pointers as well as to destroy the memory used by object variables (this is done by setting the variables to Nothing). Multiple copies of the same form can be created at runtime by using the New keyword.
Review Questions
1. Name three generic object types.
2. Describe the function of the New keyword.
3. Which type of object is more efficient to usegeneric or specific? Why?

 
< previous page page_432 next page >

If you like this book, buy it!